package test4


class Student(n:String,a:Int){
  var name=n;
  var age=a;
  def this(n:String){
    this(n,0)
  }
  def this(){
    this(null,0)
  }
  def show(): Unit ={
    println(s"这个学生名叫$name,年龄是$age")
  }
  def inc(): Unit ={
    age+=1
  }
}
object Student {
  var school="合肥北大青鸟合工大校区"
  def apply(n: String, a: Int): Student = new Student(n, a)
  def apply(n: String): Student = new Student(n,0)

  def unapply(arg: Student): Option[(String, Int)] ={
    if(arg ==null) None else Some(arg.name,arg.age)
  }

  def main(args: Array[String]): Unit = {
    var s0=Student("小张");
    s0.show();
    println(">>>>>>>>>>>>>>>>>>>>>")
    var s1=Student("小吴",21);
    s1.show()
    println(">>>>>>>>>>>>>>>>>>>>>>>>>>")
    var s2=Student("老蒋",22);
    s2.show()
    s2.inc()
    s2.show()
    println("属于 "+Student.school)
  }
}
